﻿<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="A_ManageUsers.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sec="clr-namespace:SecurityLib;assembly=SecurityLib"
             xmlns:dm="clr-namespace:DataModel;assembly=DataModel"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <dm:SaveChangesCommand x:Key="SaveChanges" />
        <dm:CancelChangesCommand x:Key="CancelChanges" />
    </UserControl.Resources>
        <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <sdk:TabControl Grid.ColumnSpan="2">
            <sdk:TabItem Header="Manage Users" sec:Security.AuthenticatedRoles="EditUsers">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Button Click="NewUser">New User</Button>
                        <Button Click="BulkNewUser" Grid.Column="1">Bulk New Users</Button>
                    </Grid>
                    
                    <ListBox Grid.Row="1" x:Name="UsersList">

                    </ListBox>
                    <Grid Grid.Column="1" Grid.RowSpan="2" DataContext="{Binding ElementName=UsersList, Path=SelectedItem}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <TextBlock>Username</TextBlock>
                        <TextBlock Grid.Row="1" Text="{Binding Path=UserName}"/>
                        <TextBlock Grid.Row="2">Comment</TextBlock>
                        <TextBox Grid.Row="3" Text="{Binding Path=Comment, Mode=TwoWay}" Margin="2"/>
                        <TextBlock Grid.Row="4">Roles</TextBlock>
                        <ListBox ItemsSource="{Binding Path=UserRoles}" Grid.Row="5" Margin="2" >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Path=Enabled, Mode=TwoWay}" Content="{Binding Path=RoleName}"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </Grid>
            </sdk:TabItem>
            <sdk:TabItem Header="Manage Roles" sec:Security.AuthenticatedRoles="EditRoles">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Button Click="NewRole">New Role</Button>
                    <ListBox Grid.Row="1" x:Name="RolesList">

                    </ListBox>
                    <Grid Grid.Column="1" Grid.RowSpan="2" DataContext="{Binding ElementName=RolesList, Path=SelectedItem}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <TextBlock>Name</TextBlock>
                        <TextBox Grid.Row="1" Text="{Binding Path=Name, Mode=TwoWay}" Margin="2"/>
                        <TextBlock Grid.Row="2">Notes</TextBlock>
                        <TextBox Grid.Row="3" Text="{Binding Path=Notes, Mode=TwoWay}" AcceptsReturn="True" TextWrapping="Wrap" Margin="2"/>
                        <TextBlock Grid.Row="4">Abilities</TextBlock>
                        <ListBox ItemsSource="{Binding Path=RoleAbilities}" Grid.Row="5" Margin="2" >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Path=Enabled, Mode=TwoWay}" Content="{Binding Path=AbilityName}"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </Grid>
            </sdk:TabItem>
            <sdk:TabItem Header="Manage Abilities" sec:Security.AuthenticatedRoles="EditAbilities">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Button Click="NewAbility">New Ability</Button>
                    <ListBox Grid.Row="1" x:Name="AbilitiesList">
                        
                    </ListBox>
                </Grid>
            </sdk:TabItem>
        </sdk:TabControl>
        <Button Command="{StaticResource SaveChanges}" Grid.Row="1">Save</Button>
        <Button Command="{StaticResource CancelChanges}" Grid.Row="1" Grid.Column="1">Cancel</Button>
    </Grid>
</UserControl>
